Skip to content

Create the management role in the database controller#368

Merged
tmablunar merged 4 commits intomasterfrom
create-manager-role-in-db-controller
Apr 28, 2026
Merged

Create the management role in the database controller#368
tmablunar merged 4 commits intomasterfrom
create-manager-role-in-db-controller

Conversation

@tmablunar
Copy link
Copy Markdown
Contributor

@tmablunar tmablunar commented Apr 28, 2026

Stacked on top of #367.

Summary

  • The controller's postgres.Database call grants the service role to the management role WITH ADMIN OPTION, but silently ignores undefined_object. A missing management role used to fail invisibly.
  • New postgres.EnsureManagerRole helper wraps an idempotent CREATE ROLE (duplicate_object → no-op).
  • PostgreSQLDatabaseReconciler now provisions the management role right after preflight, before any reconcile work touches it. The controller's runPreflight helper is renamed to prepareHost since it now does both check + setup over a single admin connection.

Test plan

  • go build ./... and go vet ./... pass
  • go test ./pkg/postgres/... (non-integration) passes
  • Integration: POSTGRESQL_CONTROLLER_INTEGRATION_HOST=... go test ./pkg/postgres/... -run TestEnsureManagerRole covers create + idempotent paths
  • After merge of Add preflight checks at start of each reconciliation loop #367, rebase this onto master and verify a deployment with no pre-existing management role reconciles cleanly

🤖 Generated with Claude Code


Note

Medium Risk
Touches database provisioning and role/privilege setup by adding automatic creation of the management role; misconfiguration (e.g., insufficient admin privileges or wrong role name) could cause reconciles to fail where they previously proceeded.

Overview
The controller now prepares a PostgreSQL host before reconciliation by reusing the admin connection to run preflight checks and proactively create the management role if missing.

This introduces postgres.EnsureManagerRole, an idempotent CREATE ROLE helper (treating duplicate_object as a no-op) with new integration tests, and renames runPreflight to prepareHost to reflect the expanded responsibilities.

Reviewed by Cursor Bugbot for commit daefeec. Configure here.

Comment thread pkg/postgres/manager_role.go Outdated
Verify controller assumptions before any side-effecting work:
- the database connection is alive
- the connecting user is a member of the configured superuser role

The role defaults to rds_superuser (RDS's conventional admin role) and
can be overridden for non-RDS deployments via --superuser-role-name.
On failure the error names the violated assumption so operators can
act on it.

Wired into PostgreSQLDatabaseReconciler and CustomRoleReconciler.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@tmablunar tmablunar force-pushed the worktree-bold-fox-ag38 branch from d04c278 to 7659b91 Compare April 28, 2026 09:32
The controller's postgres.Database call grants the service role to the
management role WITH ADMIN OPTION but silently ignores undefined_object
errors, so a missing management role used to fail invisibly. The
PostgreSQLDatabaseReconciler now creates the role on demand right after
preflight, before any reconcile work touches it.

A new postgres.EnsureManagerRole helper wraps an idempotent CREATE ROLE
(duplicate_object treated as no-op) so concurrent reconcilers and
re-runs are safe.

The controller's runPreflight method becomes prepareHost - it now does
preflight + management role provisioning over a single admin
connection.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@tmablunar tmablunar force-pushed the create-manager-role-in-db-controller branch from f5228bb to fab4b85 Compare April 28, 2026 09:33
…d injection

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@tmablunar tmablunar marked this pull request as ready for review April 28, 2026 10:33
@tmablunar tmablunar requested a review from a team as a code owner April 28, 2026 10:33
@tmablunar
Copy link
Copy Markdown
Contributor Author

bugbot run

Base automatically changed from worktree-bold-fox-ag38 to master April 28, 2026 10:42
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit daefeec. Configure here.

Comment thread pkg/postgres/manager_role.go
…ver runPreflight

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@tmablunar tmablunar merged commit 1ba0daa into master Apr 28, 2026
5 checks passed
@tmablunar tmablunar deleted the create-manager-role-in-db-controller branch April 28, 2026 11:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants